/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Text, TextArea, BlobInputList, } from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import { objNestSet} from "../../../common/tool";

export interface Props extends InternalItemProps {
    iAname?: string[];
}
export const item缺陷问题 = [
    ['技术资', [{}],  '技术资料', ],
    ['锅筒', [{}], '锅筒',  ],
    ['水冷系', [{}], '水冷系统', ],
    ['省煤系', [{}], '省煤系统', ],
    ['过热系', [{}], '过热系统', ],
    ['再热系', [{}], '再热系统', ],
    ['减温器', [{}], '减温器', ],
    ['分离器', [{}], '启动（汽水）分离器及储水箱', ],
    ['接管道', [{}], '锅炉范围内管道及主要连接管道', ],
    ['阀门', [{}], '阀门', ],
    ['其它缺', [{}], '其它', ],
];
export const itemA缺陷问题: string[] = ['缺陷备注', ];
item缺陷问题.forEach(([name, title, initIsp], i: number) => {
    itemA缺陷问题.push(name as string);
});
export const Defecthandle =
    React.forwardRef((
        {children, show, alone = true, refWidth, label, iAname,}: Props, ref
    ) => {
        let oldTitle1: any;
        let oldTitle2: any;
        const {inp, setInp} = useItemInputControl({ref});
        const itemA = React.useMemo(() => {
            return [ ...iAname ?? [], ...itemA缺陷问题 ];
        }, [ iAname]);
        const [getInpFilter] = useMeasureInpFilter(null, itemA,);
        return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={label!}>
                <Text variant="h5">{label}：</Text>
                {item缺陷问题.map(([name, titlps, item, unit]: any, i: number) => {
                    const [{t: title}, more2, more3] = titlps?.length > 0 ? titlps : ([{}] as any);
                    const {t: title2} = more2 || {};
                    const {t: title3} = more3 || {};
                    oldTitle1 = titlps?.length >= 1 ? (title ? title : oldTitle1) : '';
                    oldTitle2 = titlps?.length >= 2 ? (title2 ? title2 : oldTitle2) : '';
                    return (<React.Fragment key={i}>
                        <div css={{display: 'flex', flexWrap: 'wrap', alignItems: 'center'}}>
                            <Text>项目{i + 1} {title ?? oldTitle1} - {title2 ?? oldTitle2} {'>'} {title3} {title3 && '>'}
                                <Text css={{fontWeight: 800}}>{item}</Text>  ：</Text>
                            &nbsp;
                            <div css={{display: 'inline-flex', alignItems: 'center'}}>
                                &nbsp;检验方法
                                <BlobInputList value={inp?.[name]?.m || ''} datalist={['见结果栏']}
                                               style={{display: 'inline-flex', width: '14rem'}} rows={2}
                                               onListChange={v => objNestSet(name, 'm', v || undefined, inp, setInp)}/>
                            </div>
                            <div css={{display: 'inline-flex', alignItems: 'center',flexWrap: 'wrap'}}>
                                检验发现缺陷和问题的位置、性质、程度：
                                <BlobInputList value={inp?.[name]?.F || ''} datalist={['见结果栏']}
                                               style={{display: 'inline-flex', minWidth: '12rem',maxWidth:'100%'}} rows={3}
                                               onListChange={v => objNestSet(name, 'F', v || undefined, inp, setInp)}/>
                            </div>
                            <div css={{display: 'inline-flex', alignItems: 'center'}}>
                                &nbsp;问题处理或者整改情况
                                <BlobInputList value={inp?.[name]?.r || ''} datalist={['见结果栏']}
                                               style={{display: 'inline-flex', width: '13rem'}} rows={2}
                                               onListChange={v => objNestSet(name, 'r', v || undefined, inp, setInp)}/>
                            </div>
                        </div>
                    </React.Fragment>);
                })}
                <hr/>
                缺陷整改情况-备注：
                <TextArea value={inp?.缺陷备注 || ''} rows={4}
                          onChange={e => setInp({...inp, 缺陷备注: e.currentTarget.value || undefined})}/>
                {children}
            </InspectRecordLayout>
        );
    });
